<?php

if (!class_exists('File')) {
Loader::import('pspframework.cache.File');
}

class FileLog {

    //文件保存路径
	public $_path = null;
	
	public function __construct($options = array()) {
        $this->FileLog($options);
	}
	
	public function FileLog($options = array()) {
		$options += array('path' => LOGS);
		$this->_path = $options['path'];
	}

	public function write($type, $message) {
		$debugTypes = array('notice', 'info', 'debug');

		if ($type == 'error' || $type == 'warning') {
			$filename = $this->_path  . 'error.log';
		} elseif (in_array($type, $debugTypes)) {
			$filename = $this->_path . 'debug.log';
		} else {
			$filename = $this->_path . $type . '.log';
		}
		$output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $message . "\n";
		$log = new File($filename, true);
		if ($log->writable()) {
			return $log->append($output);
		}
	}
}
